<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    .box {
      border-bottom: 1px solid #ccc;
      width: 400px;
      position: relative;
      margin: 100px auto;
      line-height: 40px;
    }

    .box input {
      border: 0;
      width: 100%;
      height: 40px;
    }

    .box img {
      position: absolute;
      top: 12px;
      right: 2px;
      width: 30px;
      height: 30px;
    }
  </style>
</head>

<body>
  <div class="box">
    <input type="password" value="123456" />
    <img src="./images/close.png" alt="" class="img" />
  </div>
  <script>
    var eyes = document.querySelector('.img')
    var ipt = document.querySelector('input')
    var flag = true
    eyes.onclick = function () {
      if (flag) {
        eyes.src = 'images/close.png'
        ipt.type = "password"
        flag = false
      } else {
        eyes.src = 'images/open.png'
        flag = true
        ipt.type = "text"
      }
    }
  </script>
</body>

</html>